/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kpsmart.gui;

import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

/**
 * Form to create a new route
 *
 * @author Oliver Behncke
 */
public class CostForm extends javax.swing.JFrame {

    /**
     * Creates new form CostType
     */
    CostForm() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextFieldCompany = new javax.swing.JTextField();
        jFormattedTextFieldDuration = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldFrom = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldTo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jFormattedTextFieldFrequency = new javax.swing.JFormattedTextField();
        jFormattedTextFieldMaxVolume = new javax.swing.JFormattedTextField();
        jFormattedTextFieldMaxWeight = new javax.swing.JFormattedTextField();
        jFormattedTextFieldVolumecost = new javax.swing.JFormattedTextField();
        jFormattedTextFieldWeightcost = new javax.swing.JFormattedTextField();
        jButtonCUSubmit = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jComboBoxTypes = new javax.swing.JComboBox();
        jComboBoxDays = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("New Transport Route");
        setAlwaysOnTop(true);
        setResizable(false);

        jTextFieldCompany.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jFormattedTextFieldDuration.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldDuration.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldDuration.setText("0");

        jLabel3.setText("Company");

        jLabel4.setText("From");

        jTextFieldFrom.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel5.setText("To");

        jTextFieldTo.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel6.setText("Duration");

        jLabel7.setText("Day");

        jLabel8.setText("Frequency");

        jLabel9.setText("Max. Volume");

        jLabel10.setText("Max. Weight");

        jLabel11.setText("Volumecost");

        jLabel12.setText("Weightcost");

        jFormattedTextFieldFrequency.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldFrequency.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldFrequency.setText("0");

        jFormattedTextFieldMaxVolume.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldMaxVolume.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldMaxVolume.setText("0");

        jFormattedTextFieldMaxWeight.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldMaxWeight.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldMaxWeight.setText("0");

        jFormattedTextFieldVolumecost.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldVolumecost.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldVolumecost.setText("0");

        jFormattedTextFieldWeightcost.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextFieldWeightcost.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jFormattedTextFieldWeightcost.setText("0");

        jButtonCUSubmit.setText("Submit");

        jButtonCancel.setText("Cancel");

        jLabel13.setText("Type");

        jComboBoxTypes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jComboBoxDays.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(jButtonCUSubmit)
                        .addGap(76, 76, 76)
                        .addComponent(jButtonCancel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel11)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel9)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldCompany, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jTextFieldFrom, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jTextFieldTo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldDuration, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldFrequency, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldMaxVolume, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldMaxWeight, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldVolumecost, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jFormattedTextFieldWeightcost, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .addComponent(jComboBoxTypes, 0, 220, Short.MAX_VALUE)
                    .addComponent(jComboBoxDays, 0, 220, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCompany, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jComboBoxTypes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jFormattedTextFieldDuration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxDays, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jFormattedTextFieldFrequency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jFormattedTextFieldMaxVolume, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jFormattedTextFieldMaxWeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jFormattedTextFieldVolumecost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jFormattedTextFieldWeightcost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonCUSubmit)
                    .addComponent(jButtonCancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Get the name of the company
     *
     * @return company name
     */
    String getCompany() {
        return this.jTextFieldCompany.getText();
    }

    /**
     * Get the from-field value
     *
     * @return from String
     */
    String getFrom() {
        return this.jTextFieldFrom.getText();
    }

    /**
     * Get the to-field value
     *
     * @return to String
     */
    String getTo() {
        return this.jTextFieldTo.getText();
    }

    /**
     * The type of the new route
     *
     * @return routetype String
     */
    String getRoutetype() {
        return this.jComboBoxTypes.getSelectedItem().toString();
    }

    /**
     * Get duration as int
     *
     * @return duration int
     */
    int getDuration() {
        return Integer.valueOf(this.jFormattedTextFieldDuration.getText());
    }

    /**
     * Get day-field value as String
     *
     * @return day String
     */
    String getDay() {
        return this.jComboBoxDays.getSelectedItem().toString();
    }

    /**
     * Get frequency as int
     *
     * @return frequency int
     */
    int getFrequency() {
        return Integer.valueOf(this.jFormattedTextFieldFrequency.getText());
    }

    /**
     * Get max volume as int
     *
     * @return maxVolume int
     */
    int getMaxVolume() {
        return Integer.valueOf(this.jFormattedTextFieldMaxVolume.getText());
    }

    /**
     * Get max weight as int
     *
     * @return maxWeight int
     */
    int getMaxWeight() {
        return Integer.valueOf(this.jFormattedTextFieldMaxWeight.getText());
    }

    /**
     * Get volume cost as int
     *
     * @return volumecost int
     */
    int getVolumecost() {
        return Integer.valueOf(this.jFormattedTextFieldVolumecost.getText());
    }

    /**
     * Get weightcost as int
     *
     * @return weightcost int
     */
    int getWeightcost() {
        return Integer.valueOf(this.jFormattedTextFieldWeightcost.getText());
    }

    /**
     * Check if the field duration has an integer value
     *
     * @return proper boolean
     */
    boolean properDuration() {
        return isProperInteger(this.jFormattedTextFieldDuration.getText());
    }

    /**
     * Check if the field frequency has an integer value
     *
     * @return proper boolean
     */
    boolean properFrequency() {
        return isProperInteger(this.jFormattedTextFieldFrequency.getText());
    }

    /**
     * Check if the field max volume has an integer value
     *
     * @return proper boolean
     */
    boolean properMaxVolume() {
        return isProperInteger(this.jFormattedTextFieldMaxVolume.getText());
    }

    /**
     * Check if the field max weight has an integer value
     *
     * @return proper boolean
     */
    boolean properMaxWeight() {
        return isProperInteger(this.jFormattedTextFieldMaxWeight.getText());
    }

    /**
     * Check if the field volumecost has an integer value
     *
     * @return proper boolean
     */
    boolean properVolumecost() {
        return isProperInteger(this.jFormattedTextFieldVolumecost.getText());
    }

    /**
     * Check if the field weightcost has an integer value
     *
     * @return proper boolean
     */
    boolean properWeightcost() {
        return isProperInteger(this.jFormattedTextFieldWeightcost.getText());
    }

    /**
     * Check if a String has an integer value
     *
     * @return proper boolean
     */
    private boolean isProperInteger(String string) {
        try {
            Integer.valueOf(string);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * Set the values of types combo box
     * @param types 
     */
    void setTypes(Collection<String> types) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (String s : types) {
            model.addElement(s);
        }
        this.jComboBoxTypes.setModel(model);
    }

    /**
     * Set the values of the days combo box
     * @param days 
     */
    void setDays(Collection<String> days) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (String s : days) {
            model.addElement(s);
        }
        this.jComboBoxDays.setModel(model);
    }

    /**
     * Add ActionListener to submit button
     * @param l 
     */
    void addListenerToSubmit(ActionListener l) {
        this.jButtonCUSubmit.addActionListener(l);
    }

    /**
     * Add ActionListener to cancel button
     * @param l 
     */
    void addListenerToCancel(ActionListener l) {
        this.jButtonCancel.addActionListener(l);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCUSubmit;
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JComboBox jComboBoxDays;
    private javax.swing.JComboBox jComboBoxTypes;
    private javax.swing.JFormattedTextField jFormattedTextFieldDuration;
    private javax.swing.JFormattedTextField jFormattedTextFieldFrequency;
    private javax.swing.JFormattedTextField jFormattedTextFieldMaxVolume;
    private javax.swing.JFormattedTextField jFormattedTextFieldMaxWeight;
    private javax.swing.JFormattedTextField jFormattedTextFieldVolumecost;
    private javax.swing.JFormattedTextField jFormattedTextFieldWeightcost;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextFieldCompany;
    private javax.swing.JTextField jTextFieldFrom;
    private javax.swing.JTextField jTextFieldTo;
    // End of variables declaration//GEN-END:variables
}
